<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/'.YII_ENV.'/params.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/'.YII_ENV.'/params.php'
);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'response' => [
            // ...
            'formatters' => [
                \yii\web\Response::FORMAT_JSON => [
                    'class' => 'yii\web\JsonResponseFormatter',
                    'prettyPrint' => YII_DEBUG, // use "pretty" output in debug mode
                    //'encodeOptions' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
                    // ...
                ],
            ],
        ],
//        'response' => [
//            'class' => 'yii\web\Response',
//            'on beforeSend' => function ($event) {
//                if("application/json" == Yii::$app->request->getHeaders()["accept"]){
//                    var_dump(Yii::$app->getErrorHandler());die;
//                    Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
//                    $response = $event->sender;
//                    $response->data = [
//                        'success' => $response->isSuccessful,
//                        'data' => $response->data,
//                    ];
//                    $response->statusCode = 200;
//                }
//            },
//        ],
        'request' => [
            'csrfParam' => '_csrf-frontend',
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the frontend
            'name' => 'advanced-frontend',
        ],
        'log' => [
            //'flushInterval' => 20,
            'traceLevel' => 0,//YII_DEBUG ? 3 : 0,
            'targets' => [
//                [
//                    'class' => 'yii\log\FileTarget',
//                    'levels' => ['error', 'warning'],
//                ],
                'login' => [
                    'logVars' => [],
                    //'logVars' => ['_GET','_POST'],
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['info'],
                    'categories' => ['login'],
                    'logFile' => '@frontend/runtime/logs/login/'.date("Y-m-d").'.log',
                    //'maxFileSize' => 1024 * 100, //100M
                    //'maxLogFiles' => 100,
                    'exportInterval' => 1,
                    //'microtime' => true,
                    'prefix' => function() {   //日志格式自定义 回调方法
                        return "";
                    },
                    'messages' => ['111']
                ],
                'db' => [
                    'logVars' => [],
                    'class' => 'yii\log\DbTarget',
                    'categories' => ['user'],
                    'exportInterval' => 1,
                ],
                "email_target" => [
                    'logVars' => [],
                    'class' => 'yii\log\EmailTarget',
                    'mailer' => 'mailer',
                    'categories' => ['email'],
                    'message' => [
                        'from' => ['2462238234@qq.com'],
                        'to' => ['2462238234@qq.com'],
                        'subject' => 'Log email sending test',
                    ],
                ],
                [
                    'logVars' => [],
                    'class' => 'yii\log\SyslogTarget',
                    // 系统日志中的日志前缀，用于区分日志类型
                    'identity' => 'Yii',
                    'categories' => ['syslog']
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                'api/user' => 'api/user',

                '/' => 'yii2/site/home',
                'bootstrap3' => 'yii2/bootstrap3/index',
                'yii2/bootstrap3/<level2>' => 'yii2/bootstrap3/<level2>',
                'contact' => 'yii2/site/contact',

                'docs' => 'yii2/docs/index',
                'docs/install' => 'yii2/docs/install',
                'docs/install/source' => 'yii2/docs/install-source',
                'docs/install/docker' => 'yii2/docs/install-docker',
                'docs/install/docker/yiisoft' => 'yii2/docs/install-yiisoft',
                'docs/install/docker/custom' => 'yii2/docs/install-custom',
                'docs/layout' => 'yii2/docs/layout',
                'docs/life' => 'yii2/docs/life',
                'docs/structure' => 'yii2/docs/structure',
                'docs/structure/model' => 'yii2/docs/structure-model',
                'docs/structure/controller' => 'yii2/docs/structure-controller',
                'docs/structure/view' => 'yii2/docs/structure-view',

                'docs/<level1>/' => 'yii2/docs/level1',
                'docs/<level1>/<level2>' => 'yii2/docs/level2',
                'docs/<level1>/<level2>/<level3>' => 'yii2/docs/level3',
                //'docs/structure/template' => 'yii2/docs/template',

                'docker' => 'yii2/docker/index',

                'codelab' => 'yii2/codelab/index',
                'codelab/install' => 'yii2/codelab/install',
                'codelab/install/source' => 'yii2/codelab/install-source',
                'codelab/install/docker/yiisoft' => 'yii2/codelab/install-yiisoft',
                'codelab/install/docker/custom' => 'yii2/codelab/install-custom',

                'template' => 'yii2/template/index',
                'template/google-console/demo' => 'yii2/template/google-console-demo',

                // 通用路由
                '<app>/<level1>/' => 'yii2/<app>/level1',
                '<app>/<level1>/<level2>' => 'yii2/<app>/level2',
                '<app>/<level1>/<level2>/<level3>' => 'yii2/<app>/level3',
            ],
        ],
    ],
    'modules' => [
        'yii' => [
            'class' => 'frontend\modules\yii\Module',
        ],
        'cms' => [
            'class' => 'frontend\modules\cms\Module',
        ],
        'yii2' => [
            'class' => 'frontend\modules\yii2\Module',
            'controllerMap' => [
                'article' => [
                    'class' => 'frontend\modules\yii2\controllers\DocsController',
                    //'enableCsrfValidation' => false,
                    'layout' => 'main-yii'
                ],
            ]
        ],
    ],
    'params' => $params,
    'aliases' => [
        '@lvzmen/yii' => '@frontend/modules',
       // '@yii' => 'yii2'
    ],
    'controllerMap' => [
        // 用配置数组申明 "article" 控制器
        'article' => [
            'class' => 'frontend\controllers\SiteController',
            //'enableCsrfValidation' => false,
        ],
    ],

];